最近帮同事刷机,机器是HTC Desire,成功刷为HTC 官方正式版:HTC G7 Desire 2.2 ROM,ROM用的是左仔的。
下载地址:http://www.jinbo123.com/1530.html
首先,按住音量“-” 和 电源键,进入hboot,信息如下:
BRAVO PTV1 SHIP S-ON
HBOOT-0.83.0001
MICROP-031D
TOUCH PANEL-SYNT0101
RADIO-5.11.05.14
JUN 10 2010,12:12:05
当选择RECOVERY进入的时候,出现了我所不愿看到的东西,红色感叹号,没办法只好拔电池,重启进入原有系统,使用“一键无痛获取root”,同样也是参看的左仔的文章:http://www.jinbo123.com/1642.html,在这里非常感谢左仔的辛苦劳动。
这root的过程中,唯一有难度的是,安装android phone驱动,这个我自己第一次刷机的时候也没装好,最好换了好几台笔记本才把驱动装好,不过后来发现的问题的原因。在更新驱动的时候,选择android-usb-driver的时候,选择的目录不能到最底层目录,这里选择只能到android-usb-driver的父目录就可以了,然后更新驱动就不会出现无法安装驱动了。
安装驱动之后,手机就会自动重启,这个过程就别管了,但是一定要有耐心,不要觉得没反应,就去把电池,那样很容易出问题的。
获取root的过程,同时刷了recovery,这个时候再进入recovery进可以看到,刷进菜单了,同样刷机前需要wipe所有数据,这里建议wipe所有,wipe之后,就是使用flash zip from sdcard来刷机,这个时候选择之前拷贝到sdcard卡中的rom包(zip格式的),剩下的就是等待了,中间可能会提示你重启,安装提示进行就可以了。
刷机结束之后,开机进入系统,然后记得重启一次,就ok了。
刷机过程中使用的软件包,在上面两个网址中都有提供,可以直接下载,这里就不在提供了。
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="fill_parent"
android:layout_height="wrap_content" android:text="@string/hello"
/>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_marginTop="20dip">
<RelativeLayout android:id="@+id/up"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentTop="true" android:gravity="center">
<com.android.customview.CustomToggleButton
android:id="@+id/toggle_button_1" android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.android.customview.CustomToggleButton
android:id="@+id/toggle_button_2" android:layout_alignParentTop="true"
android:layout_marginLeft="10dip" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_toRightOf="@+id/toggle_button_1" />
<com.android.customview.CustomToggleButton
android:id="@+id/toggle_button_3" android:layout_alignParentTop="true"
android:layout_marginLeft="10dip" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_toRightOf="@+id/toggle_button_2" />
</RelativeLayout>
<RelativeLayout android:id="@+id/down"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="10dip" android:gravity="center"
android:layout_below="@+id/up">
<com.android.customview.CustomToggleButton
android:id="@+id/toggle_button_4" android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.android.customview.CustomToggleButton
android:id="@+id/toggle_button_5" android:layout_alignParentTop="true"
android:layout_marginLeft="10dip" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_toRightOf="@+id/toggle_button_4" />
<com.android.customview.CustomToggleButton
android:id="@+id/toggle_button_6" android:layout_alignParentTop="true"
android:layout_marginLeft="10dip" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_toRightOf="@+id/toggle_button_5" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
custom_toggle_button.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="80dip" android:layout_marginTop="0dip"
android:layout_height="46dip" android:background="@+drawable/button_bg_normal"
android:id="@+id/custom_toggle_button" android:orientation="vertical" >
<TextView android:id="@+id/toggle_button_text" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginTop="50dip"
android:textColor="@+color/red" android:layout_marginLeft="20dip" />
<ImageView android:id="@+id/toggle_button_lightbar" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_below="@+id/toggle_button_text"
android:layout_marginTop="10dip" android:src="/blog_article/@ drawable/llightbar_off/index.html"
android:layout_marginLeft="5dip" />
</LinearLayout>
CustomView.java
package com.android.customview;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
public class CustomView extends Activity implements OnClickListener {
private CustomToggleButton mToggleButton1;
private CustomToggleButton mToggleButton2;
private CustomToggleButton mToggleButton3;
private CustomToggleButton mToggleButton4;
private CustomToggleButton mToggleButton5;
private CustomToggleButton mToggleButton6;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mToggleButton1 = (CustomToggleButton)findViewById(R.id.toggle_button_1);
mToggleButton1.setText("Button1");
mToggleButton1.setOnClickListener(this);
mToggleButton2 = (CustomToggleButton)findViewById(R.id.toggle_button_2);
mToggleButton2.setText("Button2");
mToggleButton2.setOnClickListener(this);
mToggleButton3 = (CustomToggleButton)findViewById(R.id.toggle_button_3);
mToggleButton3.setText("Button3");
mToggleButton3.setOnClickListener(this);
mToggleButton4 = (CustomToggleButton)findViewById(R.id.toggle_button_4);
mToggleButton4.setText("Button4");
mToggleButton4.setOnClickListener(this);
mToggleButton5 = (CustomToggleButton)findViewById(R.id.toggle_button_5);
mToggleButton5.setText("Button5");
mToggleButton5.setOnClickListener(this);
mToggleButton6 = (CustomToggleButton)findViewById(R.id.toggle_button_6);
mToggleButton6.setText("Button6");
mToggleButton6.setOnClickListener(this);
addTrackballItems();
}
@Override
public void onClick(View v) {
int resId = v.getId();
handleButtonEvent(resId);
}
private void handleButtonEvent(int resId){
switch (resId){
case R.id.toggle_button_1:
mToggleButton1.setChecked(true);
Intent intent = new Intent();
intent.setClass(this, TestBringToFront.class);
startActivity(intent);
break;
case R.id.toggle_button_2:
mToggleButton2.setChecked(true);
break;
case R.id.toggle_button_3:
mToggleButton3.setChecked(true);
break;
case R.id.toggle_button_4:
mToggleButton4.setChecked(true);
break;
case R.id.toggle_button_5:
mToggleButton5.setChecked(true);
break;
case R.id.toggle_button_6:
mToggleButton6.setChecked(true);
break;
}
}
private int convertIndexToResId(int curIndex){
if (curIndex == 0){
return R.id.toggle_button_1;
}else if (curIndex == 1){
return R.id.toggle_button_2;
}else if (curIndex == 2){
return R.id.toggle_button_3;
}else if (curIndex == 3){
return R.id.toggle_button_4;
}else if (curIndex == 4){
return R.id.toggle_button_5;
}else {
return R.id.toggle_button_6;
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode){
case KeyEvent.KEYCODE_DPAD_UP:
searchUpFocus();
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
searchDownFocus();
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
searchRightFocus();
break;
case KeyEvent.KEYCODE_DPAD_LEFT:
searchLeftFocus();
break;
case KeyEvent.KEYCODE_DPAD_CENTER:
handleButtonEvent(convertIndexToResId(mCurTrackballIndex));
break;
}
return super.onKeyDown(keyCode, event);
}
private ArrayList<View> mTrackballItems = new ArrayList<View>();
private int mCurTrackballIndex = 0;
private int mTrackballItemsCount = 0;
private void addTrackballItems(){
mTrackballItems.add(mToggleButton1); // index = 0
mTrackballItems.add(mToggleButton2); // index = 1
mTrackballItems.add(mToggleButton3); // index = 2
mTrackballItems.add(mToggleButton4); // index = 3
mTrackballItems.add(mToggleButton5); // index = 4
mTrackballItems.add(mToggleButton6); // index = 5
mTrackballItemsCount = mTrackballItems.size();
}
private void searchUpFocus(){
if (mTrackballItems.get(mCurTrackballIndex).isSelected()){
if (mCurTrackballIndex - 3 >= 0){
mTrackballItems.get(mCurTrackballIndex).setSelected(false);
mCurTrackballIndex = mCurTrackballIndex - 3;
}else {
return;
}
}else {
mCurTrackballIndex = 0;
}
mTrackballItems.get(mCurTrackballIndex).setSelected(true);
setCurFocus(mCurTrackballIndex);
}
private void searchDownFocus(){
if (mTrackballItems.get(mCurTrackballIndex).isSelected()){
if (mCurTrackballIndex - 3 < 0){
mTrackballItems.get(mCurTrackballIndex).setSelected(false);
mCurTrackballIndex = mCurTrackballIndex + 3;
}else {
return;
}
}else {
mCurTrackballIndex = 0;
}
mTrackballItems.get(mCurTrackballIndex).setSelected(true);
setCurFocus(mCurTrackballIndex);
}
private void searchRightFocus(){
boolean isVaildUpRow = (mCurTrackballIndex >= 0) && (mCurTrackballIndex < 3);
boolean isVaildDownRow = (mCurTrackballIndex >= 3) && (mCurTrackballIndex < 5);
if (mTrackballItems.get(mCurTrackballIndex).isSelected()){
if (isVaildUpRow || isVaildDownRow){
mTrackballItems.get(mCurTrackballIndex).setSelected(false);
mCurTrackballIndex = mCurTrackballIndex + 1;
}else {
return;
}
}else {
mCurTrackballIndex = 0;
}
mTrackballItems.get(mCurTrackballIndex).setSelected(true);
setCurFocus(mCurTrackballIndex);
}
private void searchLeftFocus(){
boolean isVaildUpRow = (mCurTrackballIndex > 0) && (mCurTrackballIndex <= 3);
boolean isVaildDownRow = (mCurTrackballIndex > 3) && (mCurTrackballIndex <= 5);
if (mTrackballItems.get(mCurTrackballIndex).isSelected()){
if (isVaildUpRow || isVaildDownRow){
mTrackballItems.get(mCurTrackballIndex).setSelected(false);
mCurTrackballIndex = mCurTrackballIndex - 1;
}else {
return;
}
}else {
mCurTrackballIndex = 0;
}
mTrackballItems.get(mCurTrackballIndex).setSelected(true);
setCurFocus(mCurTrackballIndex);
}
private void setCurFocus(int curIndex){
clearAllFocus();
((CustomToggleButton)mTrackballItems.get(curIndex)).setBgFocus();
}
private void clearAllFocus(){
for (int i = 0; i < mTrackballItemsCount; i++){
((CustomToggleButton)mTrackballItems.get(i)).clearBgFocus();
}
}
}
CustomToggleButton.java
package com.android.customview;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class CustomToggleButton extends LinearLayout{
private Context mContext;
private LinearLayout mCustomToggleButton;
private TextView mText;
private ImageView mLightbar;
public CustomToggleButton(Context context) {
super(context);
mContext = context;
initView();
}
public CustomToggleButton(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
initView();
}
private void initView(){
LinearLayout l = (LinearLayout)View.inflate(mContext, R.layout.custom_toggle_button, null);
addView(l);
mCustomToggleButton = (LinearLayout)findViewById(R.id.custom_toggle_button);
// mCustomToggleButton.setOnClickListener(this);
mText = (TextView)findViewById(R.id.toggle_button_text);
mLightbar = (ImageView)findViewById(R.id.toggle_button_lightbar);
}
public void setText(String text){
mText.setText(text);
}
public void setChecked(boolean isChecked){
if (isChecked){
mLightbar.setImageResource(R.drawable.lightbar_on);
}else {
mLightbar.setImageResource(R.drawable.lightbar_off);
}
}
public void setBgFocus(){
mCustomToggleButton.setBackgroundResource(R.drawable.button_bg_focus);
}
public void clearBgFocus(){
mCustomToggleButton.setBackgroundResource(R.drawable.button_bg_normal);
}
}
正常的,我们都知道android的onTouch事件常用的事件有
onDown, onMove, onUp,onCancel...
前阵子在做一个图片拖拽效果的时候,因为拖拽的后页面的处理问题。
导致onUp事件不能够执行,我的onUp事件响应是删除掉拖拽的图片。
这样每次拖拽完成后,图片都不能被remove掉,堆叠在主界面里,体验很差。
但是又不走onTouch事件的onUp事件,导致删除不了拖动的图片。
后来想到了dispatchTouchEvent,重写了该方法,因为无论onTouch事件返回true or false都要走该方法。该方法可以理解
为父view即最外层view的touch事件处理。
我要做的就是在该方法里判断onUp事件,做删除图片的操作即可。