StackOverView又一个Android 5.0 任务管理器控件。这次这个比上次那个(MaterialRecents)要流畅些,还可以滑动删除。

StackOverView

 

a custom widget of android,like task manager of android 5.0.

介绍:

又一个Android 5.0 任务管理器控件。这次这个比上次那个(MaterialRecents)要流畅些,还可以滑动删除。

运行效果:

使用说明:

先去看看MaterialRecents的效果 http://www.jcodecraeer.com/a/opensource/2015/0915/3456.html 

 

主布局的xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?xml version= "1.0"  encoding= "utf-8" ?>
<!-- Copyright (C) 2014 The Android Open Source Project
 
      Licensed under the Apache License, Version 2.0 (the  "License" );
      you may not use  this  file except  in  compliance  with  the License.
      You may obtain a copy of the License at
 
           http: //www.apache.org/licenses/LICENSE-2.0
 
      Unless required by applicable law or agreed to  in  writing, software
      distributed under the License is distributed on an  "AS IS"  BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License  for  the specific language governing permissions and
      limitations under the License.
-->
<FrameLayout
     xmlns:android= "http://schemas.android.com/apk/res/android"
     android:layout_width= "match_parent" 
     android:layout_height= "match_parent"
     android:paddingTop= "32dp" >
 
     <!-- Recents View -->
     <com.wirelesspienetwork.overview.views.Overview
         android:id= "@+id/recents_view"
         android:layout_width= "match_parent" 
         android:layout_height= "match_parent"
         android:focusable= "true"  />
 
</FrameLayout>

item的xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?xml version= "1.0"  encoding= "utf-8" ?>
<!-- Copyright (C) 2014 The Android Open Source Project
 
      Licensed under the Apache License, Version 2.0 (the  "License" );
      you may not use  this  file except  in  compliance  with  the License.
      You may obtain a copy of the License at
 
           http: //www.apache.org/licenses/LICENSE-2.0
 
      Unless required by applicable law or agreed to  in  writing, software
      distributed under the License is distributed on an  "AS IS"  BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License  for  the specific language governing permissions and
      limitations under the License.
-->
<LinearLayout
     xmlns:android= "http://schemas.android.com/apk/res/android"
     android:layout_width= "match_parent"
     android:layout_height= "wrap_content"
     android:focusable= "true"
     android:layout_gravity= "center_horizontal|top" >
 
     <LinearLayout
         android:layout_width= "wrap_content"
         android:layout_height= "1000dp"
         android:orientation= "vertical"
         android:layout_gravity= "center_horizontal|top"
         >
 
         <Button
             android:layout_width= "wrap_content"
             android:layout_height= "wrap_content"
             android:text= "testButton" />
 
 
         </LinearLayout>
</LinearLayout>

activity

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
  * Copyright (C) 2014 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
package com.wirelesspienetwork.overviewexample;
 
import android.app.Activity;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
 
import com.wirelesspienetwork.overview.misc.Utilities;
import com.wirelesspienetwork.overview.model.OverviewAdapter;
import com.wirelesspienetwork.overview.model.ViewHolder;
import com.wirelesspienetwork.overview.views.Overview;
 
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Random;
 
/**
  * The main Recents activity that is started from AlternateRecentsComponent.
  */
public class OverviewActivity extends Activity implements Overview.RecentsViewCallbacks
{
     boolean mVisible;
     // Top level views
     Overview mRecentsView;
 
     /** Called with the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super .onCreate(savedInstanceState);
         // For the non-primary user, ensure that the SystemSericesProxy is initialized
 
         // Initialize the widget host (the host id is static and does not change)
 
         // Set the Recents layout
         setContentView(R.layout.recents);
         mRecentsView = (Overview) findViewById(R.id.recents_view);
         mRecentsView.setCallbacks( this );
         mRecentsView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
                 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
                 View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
 
         // Register the broadcast receiver to handle messages when the screen is turned off
         IntentFilter filter =  new  IntentFilter();
         filter.addAction(Intent.ACTION_SCREEN_OFF);
         filter.addAction(SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED);
 
         // Private API calls to make the shadows look better
         try  {
             Utilities.setShadowProperty( "ambientRatio" , String.valueOf(1.5f));
         catch  (IllegalAccessException e) {
             e.printStackTrace();
         catch  (InvocationTargetException e) {
             e.printStackTrace();
         }
     }
 
     @Override
     protected void onNewIntent(Intent intent) {
         super .onNewIntent(intent);
         setIntent(intent);
     }
 
     @Override
     protected void onStart() {
         super .onStart();
     }
 
     @Override
     protected void onResume() {
         super .onResume();
 
         // Mark Recents as visible
         mVisible =  true ;
 
         ArrayList<Integer> models =  new  ArrayList<>();
         for (int i = 0; i < 10; ++i)
         {
             Random random =  new  Random();
             random.setSeed(i);
             int color = Color.argb(255, random.nextInt(255), random.nextInt(255), random.nextInt(255));
             models.add(color);
         }
 
         final OverviewAdapter stack =  new  OverviewAdapter<ViewHolder<View, Integer>, Integer>(models)
         {
             @Override
             public ViewHolder onCreateViewHolder(Context context, ViewGroup parent) {
                 View v = View.inflate(context, R.layout.recents_dummy,  null );
                 return  new  ViewHolder<View, Integer>(v);
             }
 
             @Override
             public void onBindViewHolder(ViewHolder<View, Integer> viewHolder) {
                 viewHolder.itemView.setBackgroundColor(viewHolder.model);
             }
         };
 
         mRecentsView.setTaskStack(stack);
 
//        new Handler().postDelayed(new Runnable() {
//            @Override
//            public void run() {
//                stack.notifyDataSetInserted(new Integer(1), 2);
//            }
//        },2000);
 
 
     }
 
     @Override
     protected void onStop() {
         super .onStop();
     }
 
     @Override
     protected void onDestroy() {
         super .onDestroy();
     }
 
     @Override
     public void onTrimMemory(int level) {
     }
 
     @Override
     public void onAllCardsDismissed() {
     }
 
     @Override
     public void onCardDismissed(int position) {
 
     }
}

 

猜你喜欢

转载自lishuaishuai.iteye.com/blog/2297039