package com.huawei.myfavorite;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.SimpleAdapter;
public class MainActivity extends Activity implements OnItemClickListener {
GridView mGridView;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initUI();
}
private void initUI() {
mGridView = (GridView) findViewById(R.id.myGrid);
SimpleAdapter sa = new SimpleAdapter(this, getData(),
R.layout.grid_unit, new String[] { "logo", "text" }, new int[] {
R.id.ivLogo, R.id.tvName });
mGridView.setAdapter(sa);
mGridView.setOnItemClickListener(this);
}
private List<Map<String, Object>> getData() {
List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
map.put("logo", R.drawable.list);
map.put("text", getResources().getString(R.string.text_toolKit));
data.add(map);
map = new HashMap<String, Object>();
map.put("logo", R.drawable.mp3file);
map.put("text", getResources().getString(R.string.text_ring));
data.add(map);
map = new HashMap<String, Object>();
map.put("logo", R.drawable.vediofile);
map.put("text", getResources().getString(R.string.text_video));
data.add(map);
map = new HashMap<String, Object>();
map.put("logo", R.drawable.imgfile);
map.put("text", getResources().getString(R.string.text_pic));
data.add(map);
map = new HashMap<String, Object>();
map.put("logo", R.drawable.pdffile);
map.put("text", getResources().getString(R.string.text_photo));
data.add(map);
map = new HashMap<String, Object>();
map.put("logo", R.drawable.folder_file);
map.put("text", getResources().getString(R.string.text_other));
data.add(map);
return data;
}
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Intent mIntent = new Intent(this,FileListActivity.class);
switch(arg2){
case 0:mIntent.putExtra("type", CommonFiled.TYPE_TOOL);
mIntent.setClass(this,BoxActivity.class);
break;
case 1:mIntent.putExtra("type", CommonFiled.TYPE_RING);
break;
case 2:mIntent.putExtra("type", CommonFiled.TYPE_VIDEO);
break;
case 3:mIntent.putExtra("type", CommonFiled.TYPE_PICTURE);
break;
case 4:mIntent.putExtra("type", CommonFiled.TYPE_PHOTO);
break;
case 5:mIntent.putExtra("type", CommonFiled.TYPE_OTHER);
break;
}
startActivity(mIntent);
}
public boolean onSearchRequested() {
startActivity(new Intent(this,SearchableActivity.class));
return super.onSearchRequested();
}
}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.SimpleAdapter;
public class MainActivity extends Activity implements OnItemClickListener {
GridView mGridView;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initUI();
}
private void initUI() {
mGridView = (GridView) findViewById(R.id.myGrid);
SimpleAdapter sa = new SimpleAdapter(this, getData(),
R.layout.grid_unit, new String[] { "logo", "text" }, new int[] {
R.id.ivLogo, R.id.tvName });
mGridView.setAdapter(sa);
mGridView.setOnItemClickListener(this);
}
private List<Map<String, Object>> getData() {
List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
map.put("logo", R.drawable.list);
map.put("text", getResources().getString(R.string.text_toolKit));
data.add(map);
map = new HashMap<String, Object>();
map.put("logo", R.drawable.mp3file);
map.put("text", getResources().getString(R.string.text_ring));
data.add(map);
map = new HashMap<String, Object>();
map.put("logo", R.drawable.vediofile);
map.put("text", getResources().getString(R.string.text_video));
data.add(map);
map = new HashMap<String, Object>();
map.put("logo", R.drawable.imgfile);
map.put("text", getResources().getString(R.string.text_pic));
data.add(map);
map = new HashMap<String, Object>();
map.put("logo", R.drawable.pdffile);
map.put("text", getResources().getString(R.string.text_photo));
data.add(map);
map = new HashMap<String, Object>();
map.put("logo", R.drawable.folder_file);
map.put("text", getResources().getString(R.string.text_other));
data.add(map);
return data;
}
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Intent mIntent = new Intent(this,FileListActivity.class);
switch(arg2){
case 0:mIntent.putExtra("type", CommonFiled.TYPE_TOOL);
mIntent.setClass(this,BoxActivity.class);
break;
case 1:mIntent.putExtra("type", CommonFiled.TYPE_RING);
break;
case 2:mIntent.putExtra("type", CommonFiled.TYPE_VIDEO);
break;
case 3:mIntent.putExtra("type", CommonFiled.TYPE_PICTURE);
break;
case 4:mIntent.putExtra("type", CommonFiled.TYPE_PHOTO);
break;
case 5:mIntent.putExtra("type", CommonFiled.TYPE_OTHER);
break;
}
startActivity(mIntent);
}
public boolean onSearchRequested() {
startActivity(new Intent(this,SearchableActivity.class));
return super.onSearchRequested();
}
}