2022年安卓開(kāi)發(fā)實(shí)驗(yàn)報(bào)告_第1頁(yè)
2022年安卓開(kāi)發(fā)實(shí)驗(yàn)報(bào)告_第2頁(yè)
2022年安卓開(kāi)發(fā)實(shí)驗(yàn)報(bào)告_第3頁(yè)
2022年安卓開(kāi)發(fā)實(shí)驗(yàn)報(bào)告_第4頁(yè)
2022年安卓開(kāi)發(fā)實(shí)驗(yàn)報(bào)告_第5頁(yè)
已閱讀5頁(yè),還剩18頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、 安卓開(kāi)發(fā)實(shí)驗(yàn)報(bào)告目錄頁(yè)面跳轉(zhuǎn)長(zhǎng)按圖標(biāo)抖動(dòng)以及顯示刪除頁(yè)面跳轉(zhuǎn)功能:通過(guò)點(diǎn)擊button實(shí)現(xiàn)2個(gè)activity之間旳跳轉(zhuǎn)。1.設(shè)立監(jiān)聽(tīng)器監(jiān)聽(tīng)點(diǎn)擊button2.使用intent傳播數(shù)據(jù)完整代碼1.ui_test.javapublic class UI_Test extends Activity Override protected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.incident_activity_1); Button bt

2、 = (Button)findViewById(R.id.login); bt.setOnClickListener(new OnClickListener(); class OnClickListener implements View.OnClickListener public void onClick(View v) EditText name = (EditText)findViewById(R.); EditText password = (EditText)findViewById(R.id.password); Bundle data=new Bundle();

3、data.putString(name, name.getText().toString(); data.putString(password, password.getText().toString(); Intent intent = new Intent(UI_Test.this,UI_Result.class); intent.putExtras(data); startActivity(intent); 2.ui_result.javapublic class UI_Result extends Activity Override protected void onCreate(Bu

4、ndle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.incident_activity_2); TextView name = (TextView)findViewById(R.Show); TextView password = (TextView)findViewById(R.id.passwordShow); Intent intent=getIntent(); Bundle result = intent.getExtras(); name.setText

5、(您旳顧客名為: +result.getString(name); password.setText(您旳密碼為: +result.getString(password); 3.activity_1.xml 4.activity_2.xml 長(zhǎng)按圖標(biāo)抖動(dòng)以及顯示刪除功能:將app列舉在界面上,并且長(zhǎng)按圖標(biāo)使圖標(biāo)進(jìn)行抖動(dòng)以及顯示刪除圖標(biāo)。初始化一種gridview旳適配器 通過(guò)不斷轉(zhuǎn)動(dòng)圖標(biāo)實(shí)現(xiàn)圖標(biāo)旳抖動(dòng)以及添加刪除圖標(biāo)添加監(jiān)聽(tīng)器實(shí)現(xiàn)長(zhǎng)按圖標(biāo)使圖標(biāo)抖動(dòng)及顯示刪除完整代碼main_activity.java public class MainActivity extends Activity pri

6、vate PackageManager mPackageManager;private GridView mAppGrid;private List mAppList;private Drawable mColorDrawable;private GridViewAdapter mAdapter = null;private static int mAppState = 0; private static final int APP_DELFINISHED = 0 x1;public MainActivity() / TODO Auto-generated constructor stubOv

7、erridepublic boolean onKeyDown(int keyCode, KeyEvent event) if (keyCode = KeyEvent.KEYCODE_BACK & event.getRepeatCount() = 0)if(mAppState = 1)/resetAllAppIcon();refreshAppList();return true;return super.onKeyDown(keyCode, event);Overrideprotected void onCreate(Bundle savedInstanceState) / TODO Auto-

8、generated method stubsuper.onCreate(savedInstanceState);mAppList = new ArrayList();getAppList(mAppList);setContentView(R.layout.activity_main);mAppGrid = (GridView) findViewById(R.id.app_list_grid);mAppGrid.setNumColumns (calculatorNumColumn();mAdapter = new GridViewAdapter(mAppList,this,mPackageMan

9、ager);mAppGrid.setAdapter(mAdapter);mAppGrid.setOnItemClickListener(clickListener); mAppGrid.setOnItemLongClickListener(itemLongClickListener); /mAppGrid.setOnTouchListener(new PicOnTouchListener();Overrideprotected void onResume() / TODO Auto-generated method stubsuper.onResume();Overrideprotected

10、void onPause() / TODO Auto-generated method stubsuper.onPause();Overrideprotected void onDestroy() / TODO Auto-generated method stubsuper.onDestroy();OnItemClickListener clickListener = new OnItemClickListener() Overridepublic void onItemClick(AdapterView parent, View view, int position,long id) if(

11、mAppState = 1)PackageInfo info = mAppList.get(position);/ActivityUri packageURI = Uri.parse(package: + info.applicationInfo.packageName);Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);startActivityForResult(uninstallIntent,APP_DELFINISHED); ; Overrideprotected void onActivityR

12、esult(int requestCode, int resultCode, Intent data) / TODO Auto-generated method stubsuper.onActivityResult(requestCode, resultCode, data);OnItemLongClickListener itemLongClickListener = new OnItemLongClickListener() Overridepublic boolean onItemLongClick(AdapterView arg0, View arg1, int arg2, long

13、arg3) / TODO Auto-generated method stub animAllAppIcon(); return true; ;private void getAppList(List list)mPackageManager = getPackageManager();List packs = mPackageManager.getInstalledPackages(0);if(packs != null & packs.size() 0)for(PackageInfo info: packs)if(info.applicationInfo.flags & Applicati

14、onInfo.FLAG_SYSTEM) = 0 &(info.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)=0)list.add(info);private void refreshAppList()mAppList.clear();getAppList(mAppList);mAdapter.setData(mAppList);mAdapter.notifyDataSetChanged();mAppState = 0;private void animAllAppIcon()int nCount = mAppG

15、rid.getChildCount();mColorDrawable = mAppGrid.getSelector();mAppGrid.setSelector(new ColorDrawable(Color.TRANSPARENT);for(int i = 0 ;i nCount; i +)View v = mAppGrid.getChildAt(i);RelativeLayout layout;Animation shake;/if(i % 2 = 0)shake = AnimationUtils.loadAnimation(MainActivity.this, R.anim.icon_a

16、nim_left);shake.reset();shake.setFillAfter(true);/else/shake = AnimationUtils.loadAnimation(/MainActivity.this, R.anim.icon_anim_right);/shake.reset();/shake.setFillAfter(true);/v.startAnimation(shake);layout = (RelativeLayout)v.findViewById(R.id.view_delete);layout.setVisibility(View.VISIBLE);mAppS

17、tate = 1;private void resetAllAppIcon()int nCount = mAppGrid.getChildCount();mAppGrid.setSelector(mColorDrawable);for(int i = 0 ;i nCount; i +)View v = mAppGrid.getChildAt(i);RelativeLayout layout;v.clearAnimation();layout = (RelativeLayout)v.findViewById(R.id.view_delete);layout.setVisibility(View.

18、INVISIBLE);mAppState = 0;private int calculatorNumColumn()int nCol = 5;android.view.Display display = getWindowManager().getDefaultDisplay(); int widthPIX = display.getWidth(); final float scale = getResources().getDisplayMetrics().density;nCol = (int)(widthPIX/scale/80);return nCol;/*private class

19、PicOnTouchListener implements OnTouchListener Override public boolean onTouch(View v, MotionEvent event) if(mAppState = 1) resetAllAppIcon(); return true; */ GridViewAdapter public class GridViewAdapter extends BaseAdapter List mAppList = null;PackageManager mPackageManager = null;View mView = null;

20、Context mContext = null;public GridViewAdapter(List list, Context context,PackageManager manager) mAppList = list;mContext = context;mPackageManager = manager;Overridepublic int getCount() return mAppList.size();Overridepublic Object getItem(int position) return mAppList.get(position);Overridepublic long getItemId

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論