package com.ljp.laucher;
import java.util.ArrayList;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Vibrator;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.ljp.laucher.util.Configure;
import com.ljp.laucher.util.DateAdapter;
import com.ljp.laucher.util.DragGrid;
import com.ljp.laucher.util.ScrollLayout;
public class MiLaucherActivity extends Activity{
/** GridView. */
private LinearLayout linear;private RelativeLayout relate;
private DragGrid gridView;
private ScrollLayout lst_views;
TextView tv_page;// int oldPage=1;
private ImageView runImage, delImage;
LinearLayout.LayoutParams param;
TranslateAnimation left, right;
Animation up, down;
public static final int PAGE_SIZE = 8;
ArrayList<DragGrid> gridviews = new ArrayList<DragGrid>();
ArrayList<ArrayList<String>> lists = new ArrayList<ArrayList<String>>();//全部数据的集合集lists.size()==countpage;
ArrayList<String> lstDate = new ArrayList<String>();//每一页的数据
SensorManager sm;SensorEventListener lsn;boolean isClean =false;Vibrator vibrator;int rockCount=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
for (int i = 0; i < 22; i++) {
lstDate.add("" + i);
}
init();initData();
for (int i = 0; i < Configure.countPages; i++) {
lst_views.addView(addGridView(i));
}
lst_views.setPageListener(new ScrollLayout.PageListener() {
@Override
public void page(int page) {
setCurPage(page);
}
});
runImage = (ImageView) findViewById(R.id.run_image);
runAnimation();
delImage = (ImageView) findViewById(R.id.dels);
relate.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
System.out.println("LongClick");
return false;
}
});
vibrator = (Vibrator)getSystemService(VIBRATOR_SERVICE);
sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
Sensor sensor = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
lsn = new SensorEventListener() {
public void onSensorChanged(SensorEvent e) {
if (e.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
if(!isClean&&rockCount>=10){
isClean=true;rockCount=0;
vibrator.vibrate(100);
CleanItems();
return;
}
float newX = e.values[SensorManager.DATA_X];
float newY = e.values[SensorManager.DATA_Y];
float newZ = e.values[SensorManager.DATA_Z];
//if ((newX >= 18 || newY >= 20||newZ >= 20 )&&rockCount<4) {
if((newX >= 18 || newY >= 20||newZ >= 20 ) && rockCount%2==0){
rockCount++;
return;
}if((newX <= -18 || newY <= -20||newZ <= -20 ) && rockCount%2==1){
rockCount++;
return;
}
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO Auto-generated method stub
}
};
sm.registerListener(lsn, sensor, SensorManager.SENSOR_DELAY_GAME);
}
public void init() {
relate = (RelativeLayout) findViewById(R.id.relate);
lst_views = (ScrollLayout) findViewById(R.id.views);
tv_page = (TextView) findViewById(R.id.tv_page);
tv_page.setText("1");
com.ljp.laucher.util.Configure.init(MiLaucherActivity.this);
param = new LinearLayout.LayoutParams(
android.view.ViewGroup.LayoutParams.FILL_PARENT,
android.view.ViewGroup.LayoutParams.FILL_PARENT);
param.rightMargin = 100;
param.leftMargin = 20;
if (gridView != null) {
lst_views.removeAllViews();
}
}
public void initData(){
Configure.countPages = (int) Math.ceil(lstDate.size()
/ (float) PAGE_SIZE);
lists = new ArrayList<ArrayList<String>>();
for(int i=0;i<Configure.countPages;i++){
lists.add(new ArrayList<String>());
for (int j = PAGE_SIZE * i; j < (PAGE_SIZE * (i + 1) > lstDate
.size() ? lstDate.size() : PAGE_SIZE * (i + 1)); j++)
lists.get(i).add(lstDate.get(j));
}
boolean isLast=true;
for(int i=lists.get(Configure.countPages-1).size();i<PAGE_SIZE;i++){
if(isLast){lists.get(Configure.countPages-1).add(null);isLast=false;}
else lists.get(Configure.countPages-1).add("none");
}
}
public void CleanItems(){
lstDate=new ArrayList<String>();
for(int i=0;i<lists.size();i++){
for(int j=0;j<lists.get(i).size();j++){
if(lists.get(i).get(j)!=null&&!lists.get(i).get(j).equals("none")){
lstDate.add(lists.get(i).get(j).toString());System.out.println("-->"+lists.get(i).get(j).toString());
}
}
}System.out.println(lstDate.size());
initData();
lst_views.removeAllViews();
gridviews = new ArrayList<DragGrid>();
for (int i = 0; i < Configure.countPages; i++) {
lst_views.addView(addGridView(i));
}
isClean=false;
lst_views.snapToScreen(0);
}
public int getFristNonePosition(ArrayList<String> array){
for(int i=0;i<array.size();i++){
if(array.get(i)!=null &&
array.get(i).toString().equals("none")){
return i;
}
}
return -1;
}
public int getFristNullPosition(ArrayList<String> array){
for(int i=0;i<array.size();i++){
if(array.get(i)==null){
return i;
}
}
return -1;
}
public LinearLayout addGridView(int i) {
//if (lists.get(i).size() < PAGE_SIZE)
// lists.get(i).add(null);
linear = new LinearLayout(MiLaucherActivity.this);
gridView = new DragGrid(MiLaucherActivity.this);
gridView.setAdapter(new DateAdapter(MiLaucherActivity.this, lists
.get(i)));
gridView.setNumColumns(2);
gridView.setHorizontalSpacing(0);
gridView.setVerticalSpacing(0);
final int ii = i;
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
final int arg2, long arg3) {
// TODO Auto-generated method stub
if (lists.get(ii).get(arg2) == null) {
new AlertDialog.Builder(MiLaucherActivity.this)
.setTitle("添加")
.setItems(R.array.items,
new DialogInterface.OnClickListener() {
@Override
public void onClick(
DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
final String[] arrayAddItems = getResources().getStringArray(R.array.items); // array
lists.get(ii).add(arg2,arrayAddItems[which]);
lists.get(ii).remove(arg2 + 1);
if (getFristNonePosition(lists.get(ii)) >0 && getFristNullPosition(lists.get(ii)) <0) {
lists.get(ii).set(getFristNonePosition(lists.get(ii)), null);
}
if(getFristNonePosition(lists.get(ii)) <0 && getFristNullPosition(lists.get(ii)) <0){
System.out.println("===");
if(ii==Configure.countPages-1 || (getFristNullPosition(lists.get(lists.size()-1)) <0 && getFristNonePosition(lists.get(lists.size()-1)) <0)){
lists.add(new ArrayList<String>());
lists.get(lists.size()-1).add(null);
for(int i=1;i<PAGE_SIZE;i++)
lists.get(lists.size()-1).add("none");
lst_views.addView(addGridView(Configure.countPages));Configure.countPages++;
}else if(getFristNonePosition(lists.get(lists.size()-1)) >0 && getFristNullPosition(lists.get(lists.size()-1)) <0){
lists.get(lists.size()-1).set(getFristNonePosition(lists.get(lists.size()-1)), null);
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
高仿小米launcher(ZAKER)跨屏拖动item.zip (97个子文件)
高仿小米launcher(ZAKER)跨屏拖动item
MiLaucher_FinalV2.zip 1.36MB
readme.zip 12KB
MiLaucher_FinalV2
MiLaucher
project.properties 361B
.classpath 364B
.settings
org.eclipse.core.resources.prefs 142B
assets
src
com
ljp
laucher
MiLaucherActivity.java 13KB
util
DateAdapter.java 2KB
Animations.java 364B
ScrollLayout.java 6KB
DragGrid.java 11KB
Configure.java 1KB
res
anim
alpha.xml 604B
scale_out.xml 395B
del_up.xml 436B
del_done.xml 668B
scale_in.xml 395B
grid_light.xml 252B
del_down.xml 438B
out.xml 599B
drawable-mdpi
ic_launcher.png 3KB
drawable-ldpi
ic_launcher.png 2KB
values
strings.xml 264B
attrs.xml 263B
add_items.xml 295B
layout
main.xml 3KB
item.xml 592B
drawable-hdpi
icon_t_chuangyi.png 4KB
pageid.png 3KB
icon_download.png 3KB
del_check.png 3KB
blue.png 1KB
del.png 3KB
bluebg.png 1KB
icon_fav.png 4KB
greenlight.png 3KB
icon_home.png 3KB
red.png 300B
default_homebg.jpg 427KB
icon_t_meinv.png 3KB
ic_launcher.png 4KB
bin
classes
com
ljp
laucher
MiLaucherActivity$5.class 2KB
MiLaucherActivity$1.class 802B
MiLaucherActivity$7.class 1KB
MiLaucherActivity$3.class 2KB
MiLaucherActivity$5$1.class 727B
MiLaucherActivity$4$2.class 949B
MiLaucherActivity$2.class 955B
MiLaucherActivity$4$1.class 3KB
MiLaucherActivity$9.class 1KB
R$string.class 483B
R$layout.class 413B
R$id.class 531B
MiLaucherActivity$4.class 2KB
R$array.class 383B
R$attr.class 416B
MiLaucherActivity$6.class 2KB
MiLaucherActivity$10.class 2KB
R$drawable.class 822B
MiLaucherActivity$8.class 1KB
MiLaucherActivity.class 9KB
R$styleable.class 579B
R.class 651B
util
Animations.class 701B
DragGrid$3.class 1KB
DragGrid$G_ItemChangeListener.class 254B
Configure.class 2KB
DateAdapter.class 3KB
DragGrid$1.class 3KB
DragGrid$2.class 3KB
DragGrid.class 10KB
DragGrid$G_PageListener.class 239B
ScrollLayout$PageListener.class 246B
ScrollLayout.class 6KB
DragGrid$4.class 1KB
R$anim.class 600B
MiLaucher.apk 476KB
resources.ap_ 457KB
res
drawable-mdpi
ic_launcher.png 2KB
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
icon_t_chuangyi.png 1KB
pageid.png 996B
icon_download.png 737B
del_check.png 347B
blue.png 191B
del.png 466B
bluebg.png 191B
icon_fav.png 1KB
greenlight.png 4KB
icon_home.png 945B
red.png 173B
icon_t_meinv.png 1KB
ic_launcher.png 4KB
classes.dex 33KB
proguard.cfg 1KB
.project 845B
AndroidManifest.xml 802B
gen
com
ljp
laucher
R.java 6KB
共 97 条
- 1
资源评论
yimeixiaolangzai
- 粉丝: 1573
- 资源: 549
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功