import java.util.ArrayList;import com.tech.adpter.LauncherAdpter;import android.os.Bundle;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.GridView;public class LauncherActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
down();
initIconSmall();
initIconLarge();
initName();
} private View view;
private GridView grid;
private LauncherAdpter ladpter;
private int foucs ;
private void down(){
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.down, null);
grid = (GridView) view.findViewById(R.id.down_launcher);
grid.setFocusable(true);
ladpter = new LauncherAdpter(this);
grid.setAdapter(ladpter);
grid.setSelection(2);
foucs = grid.getSelectedItemPosition();
LauncherAdpter.current = foucs;
setContentView(view);
System.out.print(foucs);
}
public static ArrayList<Bitmap> bitmap = new ArrayList<Bitmap>();
private void initIconSmall(){
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.tv);
Bitmap bmp2 = BitmapFactory.decodeResource(getResources(), R.drawable.multimedia);
Bitmap bmp3 = BitmapFactory.decodeResource(getResources(), R.drawable.allapps);
Bitmap bmp4 = BitmapFactory.decodeResource(getResources(), R.drawable.setting);
Bitmap bmp5 = BitmapFactory.decodeResource(getResources(), R.drawable.game);
bitmap.add(bmp);
bitmap.add(bmp2);
bitmap.add(bmp3);
bitmap.add(bmp4);
bitmap.add(bmp5);
}
public static ArrayList<Bitmap> bit = new ArrayList<Bitmap>();
private void initIconLarge(){
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.tv_large);
Bitmap bmp2 = BitmapFactory.decodeResource(getResources(), R.drawable.multimedia_large);
Bitmap bmp3 = BitmapFactory.decodeResource(getResources(), R.drawable.allapps_large);
Bitmap bmp4 = BitmapFactory.decodeResource(getResources(), R.drawable.setting_large);
Bitmap bmp5 = BitmapFactory.decodeResource(getResources(), R.drawable.game_large);
bit.add(bmp);
bit.add(bmp2);
bit.add(bmp3);
bit.add(bmp4);
bit.add(bmp5);
}
public static ArrayList<Integer> name = new ArrayList<Integer>();
private void initName(){
name.add(R.string.tv);
name.add(R.string.media);
name.add(R.string.apps);
name.add(R.string.settings);
name.add(R.string.game);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event){ switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
grid.setFocusable(true);
foucs--;
if(foucs<0){
foucs=4;
}
LauncherAdpter.current = foucs;
grid.setAdapter(ladpter);
System.out.println(foucs);
grid.setSelection(foucs);
return false;
case KeyEvent.KEYCODE_DPAD_RIGHT:
grid.setFocusable(true);
foucs++;
if(foucs>4){
foucs=0;
}
LauncherAdpter.current = foucs;
grid.setAdapter(ladpter);
grid.setSelection(foucs);
System.out.println(foucs);
return false;
case KeyEvent.KEYCODE_DPAD_CENTER:
if(foucs == 0){
packName = "";
className = "";
startActivity();
break;
}else if(foucs ==1){
packName = "";
className = "";
startActivity();
break;
}else if(foucs == 2){
packName = "";
className = "";
startActivity();
break;
}else if(foucs == 3){
packName = "com.android.settings";
className = "Settings";
startActivity();
break;
}else if(foucs == 4){
packName = "";
className = "";
startActivity();
break;
}
return false;
}
return true;
}
private String packName;
private String className;
public void startActivity(){
ComponentName comName = new ComponentName(packName,className);
Intent intent = new Intent();
intent.setComponent(comName);
startActivity(intent);
}
}
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.GridView;public class LauncherActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
down();
initIconSmall();
initIconLarge();
initName();
} private View view;
private GridView grid;
private LauncherAdpter ladpter;
private int foucs ;
private void down(){
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.down, null);
grid = (GridView) view.findViewById(R.id.down_launcher);
grid.setFocusable(true);
ladpter = new LauncherAdpter(this);
grid.setAdapter(ladpter);
grid.setSelection(2);
foucs = grid.getSelectedItemPosition();
LauncherAdpter.current = foucs;
setContentView(view);
System.out.print(foucs);
}
public static ArrayList<Bitmap> bitmap = new ArrayList<Bitmap>();
private void initIconSmall(){
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.tv);
Bitmap bmp2 = BitmapFactory.decodeResource(getResources(), R.drawable.multimedia);
Bitmap bmp3 = BitmapFactory.decodeResource(getResources(), R.drawable.allapps);
Bitmap bmp4 = BitmapFactory.decodeResource(getResources(), R.drawable.setting);
Bitmap bmp5 = BitmapFactory.decodeResource(getResources(), R.drawable.game);
bitmap.add(bmp);
bitmap.add(bmp2);
bitmap.add(bmp3);
bitmap.add(bmp4);
bitmap.add(bmp5);
}
public static ArrayList<Bitmap> bit = new ArrayList<Bitmap>();
private void initIconLarge(){
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.tv_large);
Bitmap bmp2 = BitmapFactory.decodeResource(getResources(), R.drawable.multimedia_large);
Bitmap bmp3 = BitmapFactory.decodeResource(getResources(), R.drawable.allapps_large);
Bitmap bmp4 = BitmapFactory.decodeResource(getResources(), R.drawable.setting_large);
Bitmap bmp5 = BitmapFactory.decodeResource(getResources(), R.drawable.game_large);
bit.add(bmp);
bit.add(bmp2);
bit.add(bmp3);
bit.add(bmp4);
bit.add(bmp5);
}
public static ArrayList<Integer> name = new ArrayList<Integer>();
private void initName(){
name.add(R.string.tv);
name.add(R.string.media);
name.add(R.string.apps);
name.add(R.string.settings);
name.add(R.string.game);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event){ switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
grid.setFocusable(true);
foucs--;
if(foucs<0){
foucs=4;
}
LauncherAdpter.current = foucs;
grid.setAdapter(ladpter);
System.out.println(foucs);
grid.setSelection(foucs);
return false;
case KeyEvent.KEYCODE_DPAD_RIGHT:
grid.setFocusable(true);
foucs++;
if(foucs>4){
foucs=0;
}
LauncherAdpter.current = foucs;
grid.setAdapter(ladpter);
grid.setSelection(foucs);
System.out.println(foucs);
return false;
case KeyEvent.KEYCODE_DPAD_CENTER:
if(foucs == 0){
packName = "";
className = "";
startActivity();
break;
}else if(foucs ==1){
packName = "";
className = "";
startActivity();
break;
}else if(foucs == 2){
packName = "";
className = "";
startActivity();
break;
}else if(foucs == 3){
packName = "com.android.settings";
className = "Settings";
startActivity();
break;
}else if(foucs == 4){
packName = "";
className = "";
startActivity();
break;
}
return false;
}
return true;
}
private String packName;
private String className;
public void startActivity(){
ComponentName comName = new ComponentName(packName,className);
Intent intent = new Intent();
intent.setComponent(comName);
startActivity(intent);
}
}
解决方案 »
- 求解—android应用程序级变量在调用拍照程序之后被回收?
- Android中double类型计算
- 请教一个关于同时上传图片和文字的例子
- 关于多个broadCastReciever并行还是串行的问题
- android 布局 <include>标签 属性值丢失的问题
- android strings.xml 语言切换
- 求android经典书籍推荐,最好是国外的
- sqlite3 not found & push not found
- TabActivity跳转同一Avtivity不刷新
- android如何实现在图片上像地图一样在指定的位置上定位
- android service绑定失败
- 求助大家一个问题:onCreate中调用线程与方法的问题!谢谢。
在每个case里面加上Log.i("Test", "对应的keyCode");来判断到底是没响应呢?还是有响应,但是响应处理的代码有误。